import 'dart:convert' as convert;
import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
import 'package:get/get.dart';
import 'package:sp_util/sp_util.dart';
import 'package:yp/Xwidgets/cache_image.dart';
import 'package:yp/config/config.dart';
import 'package:yp/helper.dart';
import 'package:yp/router.dart';
import 'package:yp/services/api.dart';

import '../../logic.dart';

class HotSellingGoodsPage extends StatefulWidget {
  final Map<String, dynamic> map;
  final List goodsList;
  final List angleInformationList;
  int perPageSize = 10;
  int haha222 = 2;

  HotSellingGoodsPage(
      {Key key,
      this.map,
      this.goodsList,
      this.angleInformationList,
      this.perPageSize = 10,
      this.haha222 = 2});

  @override
  State<StatefulWidget> createState() {
    return _HotSellingGoodsPage();
  }
}

class _HotSellingGoodsPage extends State<HotSellingGoodsPage> {
  final MallLogic logic = Get.put(MallLogic());

  Map<String, dynamic> dataMap;
  List listMap = [];
  List angleInformationList = [];
  List goodsList = [];

  @override
  void initState() {
    super.initState();
    dataMap = widget.map;
    _init();
  }

  _init() {
    if (dataMap['widgets_sign'] == 4) {
      Map<String, dynamic> postData = {};

      Map locationMap = SpUtil.getObject(Config.USER_CURRENT_LOCATION);
      // print("locationMaplocationMaplocationMap=${locationMap['AMapResult']}");
      var prv_num_id = "";
      var city_num_id = "";
      var city_area_num_id = "";
      if (locationMap != null &&
          locationMap['AMapResult'] != null &&
          locationMap['AMapResult']['adCode'] != null) {
        var a = locationMap['AMapResult']['adCode'].split("");
        var b = locationMap['AMapResult']['adCode'].split("");
        if (a.length > 5) {
          city_area_num_id = locationMap['AMapResult']['adCode'];

          a[2] = "0";
          a[3] = "0";
          a[4] = "0";
          b[4] = "0";
          a[5] = "0";
          b[5] = "0";
        }
        prv_num_id = a.join();
        city_num_id = b.join();
      }

      var params = jsonDecode(dataMap['widgets_data_params']);

      String selectType = params['select_type'];

      var shopId = SpUtil.getInt("storeShopNum");
      var isThird = SpUtil.getInt(Config.IS_CHANGE_SHOP) ?? 0;

      if (isThird == 1) {
        shopId = SpUtil.getInt("thirdStoreShopNum");
      }

      print(">>>>>>>thirdStoreShopNum= $shopId");
      //预售
      if (selectType == "spell_mass_goods") {
        var styleList = [];
        dataMap["style"].forEach((item) {
          styleList.add(item['style_num_id']);
        });
        postData = {
          "shop_id": shopId,
          "shop_num_id": shopId,
          "page_num": 1,
          "page_size": 10,
          "use_platform": 3,
          "item_num_ids": styleList,
        };
      }
      //自选商品
      if (selectType == "goods") {
        var styleList = [];
        dataMap["style"].forEach((item) {
          styleList.add(item['style_num_id']);
        });
        var map = convert.jsonDecode(dataMap['widgets_data_params']);
        postData = {
          "style_num_ids": styleList,
          "shop_id": shopId,
          "shop_num_id": shopId,
          "nublayout": map['nublayout'],
          "nubnub": map['nubnub'],
          "page_no": 1,
          "page_size": dataMap['style'].length,
          "use_platform": 2,
          "widgets_data_id": dataMap["widgets_data_id"],
          "sold_type": params["sold_type"],
        };
        print('optionalGoods(postData) params is goodsMap length is:$postData');
        Api.optionalGoods(postData).listen((event) {
          if (event['code'] == 0) {
            listMap = event["lists"];
            print(
                'optionalGoods(postData)  goodsMap length is:${listMap.length}');
            if (mounted) {
              setState(() {});
            }
          }
        });
      }
      //为你推荐
      if (selectType == "custom") {
        postData = {
          "prv_num_id": prv_num_id,
          "city_num_id": city_num_id,
          "city_area_num_id": city_area_num_id,
          "is_recommend": 1,
          "shop_id": shopId,
          "shop_num_id": shopId,
          "page_no": 1,
          "page_size": 10,
          "use_platform": 3,
          "sold_type": params["sold_type"],
          'access_token': SpUtil.getString('token'),
        };
        print("goods.api.service.searchstyle === $postData");
        Api.recommendGoods(postData).listen((event) {
          print("获取推荐商品列表custom:$event");
          if (event["code"] == 0) {
            listMap = event["lists"];
            if (mounted) {
              setState(() {});
            }
          }
        });
      }
      //预售
      if (selectType == "hot") {
        postData = {
          "prv_num_id": prv_num_id,
          "city_num_id": city_num_id,
          "city_area_num_id": city_area_num_id,
          "is_hot": 1,
          "shop_id": shopId,
          "shop_num_id": shopId,
          "page_no": 1,
          "page_size": 10,
          "use_platform": 3,
          "sold_type": params["sold_type"],
          'access_token': SpUtil.getString('token'),
        };
        Api.recommendGoods(postData).listen((event) {
          print("获取推荐商品列表:$event");
          if (event["code"] == 0) {
            listMap = event["lists"];
            if (mounted) {
              setState(() {});
            }
          }
        });
      }
      //新款力荐
      if (selectType == "new") {
        postData = {
          "prv_num_id": prv_num_id,
          "city_num_id": city_num_id,
          "city_area_num_id": city_area_num_id,
          "is_new": 1,
          "shop_id": shopId,
          "shop_num_id": shopId,
          "page_no": 1,
          "page_size": 10,
          "use_platform": 3,
          'access_token': SpUtil.getString('token'),
        };
        // return;
        Api.recommendGoods(postData).listen((event) {
          print("获取推荐商品列表new:$event");
          if (event["code"] == 0) {
            listMap = event["lists"];
            if (mounted) {
              setState(() {});
            }
          }
        });
      }
    }
  }

  @override
  Widget build(BuildContext context) {
    // return Container();
    dataMap = widget.map;
    print("goods.api.service.searchstyle=$goodsList");
    // listMap = widget.goodsList;
    angleInformationList = widget.angleInformationList ?? [];
    var map = convert.jsonDecode(dataMap['widgets_data_params']);
    return Container(
      color: Colors.white,
      margin: EdgeInsets.only(
        top: setWidth(20),
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Offstage(
            offstage: dataMap['widgets_data_show_title'] == 0,
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Row(
                      children: [
                        Padding(
                          padding: EdgeInsets.only(
                            left: setWidth(16),
                            top: setWidth(20),
                            right: setWidth(12),
                            bottom: setWidth(16),
                          ),
                          child: Container(
                            decoration: BoxDecoration(
                              color: Color(0xffea5504),
                              borderRadius: BorderRadius.circular(setWidth(3)),
                            ),
                            width: setWidth(6),
                            height: setWidth(32),
                          ),
                        ),
                        Text.rich(
                          TextSpan(
                            children: [
                              TextSpan(
                                text: dataMap['widgets_data_title'],
                                style: TextStyle(
                                  color: Color(0xff333333),
                                  fontSize: 15,
                                ),
                              ),
                              WidgetSpan(
                                child: SizedBox(width: 4),
                              ),
                              TextSpan(
                                text: dataMap['widgets_data_sub_title'],
                                style: TextStyle(
                                  color: Colors.black.withOpacity(0.3),
                                  fontSize: 12,
                                ),
                              ),
                            ],
                          ),
                        ),
                      ],
                    ),
                    Offstage(
                      offstage: dataMap['widgets_data_show_more'] == 0,
                      child: Row(
                        children: [
                          InkWell(
                            onTap: () {
                              print(' 更多按钮点击事件 商品 横排 $dataMap');

                              jump(
                                  url: dataMap["widgets_data_more_type"]
                                      .toString(),
                                  model: {
                                    "linktarget":
                                        dataMap["widgets_data_more_id"],
                                  });
                            },
                            child: Container(
                              height: setWidth(60),
                              width: setWidth(80),
                              alignment: Alignment.centerRight,
                              child: Text(
                                '更多',
                                style: TextStyle(
                                  color: Color(0xff999999),
                                  fontSize: 12,
                                ),
                              ),
                            ),
                          ),
                          SizedBox(
                            width: setWidth(20),
                          ),
                        ],
                      ),
                    ),
                  ],
                ),
                Divider(
                  height: setWidth(4),
                  color: Color(0xffefefef),
                ),
              ],
            ),
          ),
          // vertical 竖排   horizontal 横排
          map['layout'] == 'horizontal' && listMap.length > 0
              ? Container(
                  width: setWidth(750),
                  height: setWidth(400),
                  padding: EdgeInsets.symmetric(horizontal: setWidth(20)),
                  child: ListView.separated(
                    scrollDirection: Axis.horizontal,
                    itemBuilder: (context, index) {
                      return _itemWidget(index: index);
                    },
                    separatorBuilder: (BuildContext context, int index) {
                      return SizedBox(width: setWidth(15));
                    },
                    itemCount: listMap.length,
                  ),
                )
              : map['cols'] == 2 || map['cols'] == 3 && listMap.length > 0
                  ? Container(
                      child: StaggeredGridView.countBuilder(
                        shrinkWrap: true,
                        padding: EdgeInsets.symmetric(horizontal: setWidth(20)),
                        crossAxisCount: map['cols'],
                        itemCount: listMap.length, // - 2,
                        physics: NeverScrollableScrollPhysics(),
                        itemBuilder: (BuildContext context, int index) {
                          double cols = map['cols'] == 2 ? 314 : 230;
                          // print('_verticalItemWidget(index: index):$index');
                          return _verticalItemWidget(index: index, cols: cols);
                        },
                        staggeredTileBuilder: (index) => StaggeredTile.fit(1),
                        mainAxisSpacing: map['cols'] == 2
                            ? setWidth(14)
                            : setWidth(5), // 排间距
                        crossAxisSpacing: map['cols'] == 2
                            ? setWidth(14)
                            : setWidth(5), // 列间距
                      ),
                    )
                  : listMap.length > 0
                      ? Container(
                          padding: EdgeInsets.only(
                            bottom: setWidth(20),
                          ),
                          child: ListView.builder(
                            shrinkWrap: true,
                            padding: EdgeInsets.zero,
                            physics: NeverScrollableScrollPhysics(),
                            itemBuilder: (context, index) {
                              return _verticalSingleItemWidget(index: index);
                            },
                            itemCount: listMap.length,
                          ),
                        )
                      : Container(),
        ],
      ),
    );
  }

  // 横排 item
  _itemWidget({
    int index,
  }) {
    String priceStr = '', oldPriceStr = '', tiShi = '';
    bool oldBool = false;
    if (listMap[index]['is_seckill'] == 1) {
      // 秒杀商品
      priceStr = listMap[index]['price'].toString();
      oldBool = listMap[index]['mkt_price'] > listMap[index]['price']; // 显示旧价格
      oldPriceStr = listMap[index]['mkt_price'].toString();
    } else if (listMap[index]['is_pre_sale'] == 1) {
      priceStr = listMap[index]['price'].toString();
      oldBool = listMap[index]['mkt_price'] > listMap[index]['price']; // 显示旧价格
      oldPriceStr = listMap[index]['mkt_price'].toString();
    } else {
      if (listMap[index]['expect_price'] > 0) {
        priceStr = listMap[index]['expect_price'].toString();
        tiShi = '折后';
        oldBool = listMap[index]['mkt_price'] >
            listMap[index]['expect_price']; // 显示旧价格
        oldPriceStr = listMap[index]['mkt_price'].toString();
      } else {
        priceStr = listMap[index]['price'].toString();
        oldBool =
            listMap[index]['mkt_price'] > listMap[index]['price']; // 显示旧价格
        oldPriceStr = listMap[index]['mkt_price'].toString();
      }
    }
    bool soldOutBool = listMap[index]['style_store'] <= 0;
    // 标签
    bool labelBool = false;
    String labelStr = '';
    if (angleInformationList.length > 0) {
      Map labelMap = angleInformationList[index];
      if (labelMap['item_promotion']['parameter_corner'] != null &&
          labelMap['item_promotion']['parameter_corner'] != '') {
        labelStr = labelMap['item_promotion']['parameter_corner'];
        labelBool = true;
      }
    }

    return InkWell(
      onTap: () {
        String itemNumId =
            listMap[index]['default_item_num_id']?.toString() ?? '';
        String styleNumId = listMap[index]['style_num_id']?.toString() ?? '';
        String shopId = listMap[index]['shop_num_id']?.toString() ?? '';
        String cat1Id = listMap[index]['cat1_id']?.toString() ?? '';
        String ecStyleNumId =
            listMap[index]['ec_style_num_id'].toString() ?? '';
        Get.toNamed(RouteConfig.goodsDetail, arguments: {
          'itemNumId': itemNumId,
          'styleNumId': styleNumId,
          'shopId': shopId,
          'cat1Id': cat1Id,
          'ecStyleNumId': ecStyleNumId,
          'typeIndex': listMap[index]['is_pre_sale'],
        });
      },
      child: Container(
        width: setWidth(220),
        height: setWidth(370),
        padding: EdgeInsets.only(
          top: setWidth(20),
        ),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Stack(
              children: [
                CachedImage(
                  width: setWidth(220),
                  height: setWidth(220),
                  margin: EdgeInsets.zero,
                  scale: BoxFit.fill,
                  path: listMap[index]['image_default_id'],
                ),
                Positioned(
                  left: setWidth(50),
                  top: setWidth(50),
                  child: soldOutBool
                      ? Container(
                          width: setWidth(120),
                          height: setWidth(120),
                          alignment: Alignment.center,
                          decoration: BoxDecoration(
                            color: Color(0xffbbbbbb).withOpacity(0.7),
                            borderRadius: BorderRadius.circular(setWidth(60)),
                          ),
                          child: Text(
                            '售罄',
                            style: TextStyle(
                              color: Colors.white,
                              fontSize: 15,
                            ),
                          ),
                        )
                      : SizedBox(),
                ),
              ],
            ),
            SizedBox(
              height: setWidth(18),
            ),
            Row(
              children: [
                if (listMap[index]['is_seckill'] == 1)
                  Container(
                    constraints: BoxConstraints(
                      maxWidth: setWidth(220),
                      minWidth: 0,
                    ),
                    height: setWidth(26),
                    padding: EdgeInsets.symmetric(horizontal: setWidth(4)),
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(setWidth(4)),
                      border: Border.all(
                        width: setWidth(1),
                        color: Colors.red,
                      ),
                    ),
                    child: Text(
                      "秒杀",
                      maxLines: 1,
                      overflow: TextOverflow.ellipsis,
                      style: TextStyle(
                        color: Colors.red,
                        fontSize: 10,
                        height: 1.3,
                      ),
                    ),
                  ),
                if (listMap[index]['is_pre_sale'].toString() == "1")
                  Container(
                    margin: const EdgeInsets.only(right: 3),
                    padding: const EdgeInsets.only(
                        top: 0, bottom: 0, left: 1, right: 1),
                    decoration: BoxDecoration(
                      border: Border.all(color: const Color(0xff48C13D)),
                      borderRadius: BorderRadius.circular(3),
                    ),
                    child: Text(
                      '预售',
                      style: TextStyle(
                        color: const Color(0xff48C13D),
                        fontSize: 10,
                        height: 1.3,
                      ),
                    ),
                  ),
                Container(
                  width: listMap[index]['is_seckill'] == 1 ||
                          listMap[index]['is_pre_sale'] == 1
                      ? setWidth(155)
                      : setWidth(200),
                  child: Text(
                    listMap[index]['title'], //'智能油烟机',
                    maxLines: 1,
                    overflow: TextOverflow.ellipsis,
                    style: TextStyle(
                      color: Color(0xff222222),
                      fontSize: 13,
                    ),
                  ),
                ),
              ],
            ),
            // if (commodityInfo['is_seckill'] == 1)
            SizedBox(
              height: setWidth(6),
            ),
            Row(
              children: [
                Container(
                  height: setWidth(26),
                  padding: EdgeInsets.symmetric(horizontal: setWidth(4)),
                  decoration: labelBool
                      ? BoxDecoration(
                          borderRadius: BorderRadius.circular(setWidth(4)),
                          border: Border.all(
                            width: setWidth(1),
                            color: Colors.red,
                          ),
                        )
                      : null,
                  child: labelBool
                      ? Text(
                          labelStr,
                          maxLines: 1,
                          overflow: TextOverflow.ellipsis,
                          style: TextStyle(
                            color: Colors.red,
                            fontSize: 10,
                            height: 1.3,
                          ),
                        )
                      : null,
                ),
              ],
            ),
            SizedBox(
              height: setWidth(6),
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Expanded(
                  child: Container(
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text.rich(
                          TextSpan(
                            children: [
                              TextSpan(
                                text: tiShi + '¥',
                                style: TextStyle(
                                  color: Color(0xff333333),
                                  fontSize: 10,
                                ),
                              ),
                              TextSpan(
                                text: parsePrice(priceStr),
                                style: TextStyle(
                                  color: Color(0xff333333),
                                  fontSize: 14,
                                ),
                              ),
                              // TextSpan(
                              //   text: listMap[index]['commission_amount'] > 0 ? '赚${listMap[index]['commission_amount']}' : '',
                              //   style: TextStyle(
                              //     color: Color(0xffdd2f3e),
                              //     fontSize: 10,
                              //   ),
                              // ),
                            ],
                          ),
                          maxLines: 1,
                          overflow: TextOverflow.ellipsis,
                        ),
                        Offstage(
                          offstage: !oldBool,
                          child: Text.rich(
                            TextSpan(
                              children: [
                                TextSpan(
                                  text: '¥$oldPriceStr',
                                  style: TextStyle(
                                    color: Color(0xffaaaaaa),
                                    fontSize: 10,
                                    decoration: TextDecoration.lineThrough,
                                  ),
                                ),
                              ],
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
                // InkWell(
                //   onTap: () {
                //     print(' 加入购物车图片点击事件！！！ index = $index');
                //     if (!soldOutBool) {
                //       if (listMap[index]['nospec'] == '1') {
                //         logic.addShoppingCart(
                //           ec_shop_num_id:
                //               listMap[index]['shop_num_id'].toString(),
                //           item_num_id:
                //               listMap[index]['default_item_num_id'].toString(),
                //           style_num_id:
                //               listMap[index]['style_num_id'].toString(),
                //           ec_style_num_id:
                //               listMap[index]['ec_style_num_id'].toString(),
                //         );
                //       }
                //     }
                //   },
                //   child: Image.asset(
                //     'assets/images/shoppingCart_image.png',
                //     width: setWidth(42),
                //     height: setWidth(42),
                //     color: !soldOutBool ? Color(0xffEA5504) : Color(0xffcccccc),
                //     fit: BoxFit.cover,
                //   ),
                // ),
              ],
            ),
          ],
        ),
      ),
    );
  }

  // 竖排 每行两列
  _verticalItemWidget({int index, double cols}) {
    String priceStr = '', oldPriceStr = '', tiShi = '';
    bool oldBool = false;
    if (listMap[index]['is_seckill'] == 1) {
      // 秒杀商品
      priceStr = listMap[index]['price'].toString();
      oldBool = listMap[index]['mkt_price'] > listMap[index]['price']; // 显示旧价格
      oldPriceStr = listMap[index]['mkt_price'].toString();
    } else if (listMap[index]['is_pre_sale'] == 1) {
      priceStr = listMap[index]['price'].toString();
      oldBool = listMap[index]['mkt_price'] > listMap[index]['price']; // 显示旧价格
      oldPriceStr = listMap[index]['mkt_price'].toString();
    } else {
      if (listMap[index]['expect_price'] > 0) {
        priceStr = '${listMap[index]['expect_price'].toString()}';
        tiShi = '折后';
        oldBool = listMap[index]['mkt_price'] >
            listMap[index]['expect_price']; // 显示旧价格
        oldPriceStr = listMap[index]['mkt_price'].toString();
      } else {
        priceStr = listMap[index]['price'].toString();
        oldBool =
            listMap[index]['mkt_price'] > listMap[index]['price']; // 显示旧价格
        oldPriceStr = listMap[index]['mkt_price'].toString();
      }
    }
    bool soldOutBool = listMap[index]['style_store'] <= 0;
    // 标签
    bool labelBool = false;
    String labelStr = '';
    if (angleInformationList.length > 0 &&
        index < angleInformationList.length) {
      Map labelMap = angleInformationList[index];
      if (labelMap['item_promotion']['parameter_corner'] != null &&
          labelMap['item_promotion']['parameter_corner'] != '') {
        labelStr = labelMap['item_promotion']['parameter_corner'];
        labelBool = true;
      }
    }

    return InkWell(
      onTap: () {
        String itemNumId =
            listMap[index]['default_item_num_id']?.toString() ?? '';
        String styleNumId = listMap[index]['style_num_id']?.toString() ?? '';
        String shopId = listMap[index]['shop_num_id']?.toString() ?? '';
        String cat1Id = listMap[index]['cat1_id']?.toString() ?? '';
        String ecStyleNumId =
            listMap[index]['ec_style_num_id'].toString() ?? '';
        Get.toNamed(RouteConfig.goodsDetail, arguments: {
          'itemNumId': itemNumId,
          'styleNumId': styleNumId,
          'shopId': shopId,
          'cat1Id': cat1Id,
          'ecStyleNumId': ecStyleNumId,
          'typeIndex': listMap[index]['is_pre_sale'],
        });
      },
      child: Container(
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.circular(setWidth(10)),
        ),
        padding: EdgeInsets.only(
          left: setWidth(16),
          top: setWidth(18),
          right: setWidth(16),
          bottom: setWidth(20),
        ),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Stack(
              children: [
                CachedImage(
                  width: setWidth(cols),
                  height: setWidth(cols),
                  margin: EdgeInsets.zero,
                  scale: BoxFit.fill,
                  path: listMap[index]['image_default_id'],
                ),
                Positioned(
                  left: setWidth(97),
                  top: setWidth(106),
                  child: soldOutBool
                      ? Container(
                          width: setWidth(120),
                          height: setWidth(120),
                          alignment: Alignment.center,
                          decoration: BoxDecoration(
                            color: Color(0xffbbbbbb).withOpacity(0.7),
                            borderRadius: BorderRadius.circular(setWidth(60)),
                          ),
                          child: Text(
                            '售罄',
                            style: TextStyle(
                              color: Colors.white,
                              fontSize: 15,
                            ),
                          ),
                        )
                      : SizedBox(),
                ),
              ],
            ),
            SizedBox(
              height: setWidth(6),
            ),
            Row(
              children: [
                Visibility(
                  visible: listMap[index]['is_pre_sale'] == 1,
                  child: Container(
                    margin: const EdgeInsets.only(right: 3),
                    padding: const EdgeInsets.only(
                        top: 0, bottom: 0, left: 1, right: 1),
                    decoration: BoxDecoration(
                      border: Border.all(color: const Color(0xff48C13D)),
                      borderRadius: BorderRadius.circular(3),
                    ),
                    child: Text('预售',
                        style: TextStyle(
                            color: const Color(0xff48C13D), fontSize: 12)),
                  ),
                ),
                Visibility(
                  visible: listMap[index]['is_seckill'] == 1,
                  child: Container(
                    margin: const EdgeInsets.only(right: 3),
                    padding: const EdgeInsets.only(
                        top: 0, bottom: 0, left: 1, right: 1),
                    decoration: BoxDecoration(
                      border: Border.all(color: Colors.red),
                      borderRadius: BorderRadius.circular(3),
                    ),
                    child: Text('秒杀',
                        style: TextStyle(color: Colors.red, fontSize: 12)),
                  ),
                ),
                Expanded(
                  child: Text(
                    listMap[index]['title'],
                    maxLines: 1,
                    overflow: TextOverflow.ellipsis,
                    style: TextStyle(
                      color: Color(0xff222222),
                      fontSize: 13,
                    ),
                  ),
                ),
              ],
            ),
            // SizedBox(
            //   height: setWidth(12),
            // ),
            Row(
              children: [
                Container(
                  constraints: BoxConstraints(
                    maxWidth: setWidth(314),
                    minWidth: 0,
                  ),
                  height: setWidth(30),
                  padding: EdgeInsets.symmetric(horizontal: setWidth(4)),
                  decoration: labelBool
                      ? BoxDecoration(
                          borderRadius: BorderRadius.circular(setWidth(4)),
                          border: Border.all(
                            width: setWidth(1),
                            color: Colors.red,
                          ),
                        )
                      : null,
                  child: labelBool
                      ? Text(
                          labelStr,
                          maxLines: 1,
                          overflow: TextOverflow.ellipsis,
                          style: TextStyle(
                            color: Colors.red,
                            fontSize: 10,
                          ),
                        )
                      : null,
                ),
              ],
            ),

            // Offstage(
            //   offstage: index % 3 == 0,
            //   child: Column(
            //     crossAxisAlignment: CrossAxisAlignment.start,
            //     children: [
            //       Wrap(
            //         direction: Axis.horizontal,
            //         spacing: setWidth(10), //列间距
            //         alignment: WrapAlignment.start,
            //         children: titleList.map((titleStr) {
            //           return Container(
            //             padding: EdgeInsets.symmetric(
            //               horizontal: setWidth(8),
            //               vertical: setWidth(4),
            //             ),
            //             decoration: BoxDecoration(
            //               borderRadius: BorderRadius.circular(setWidth(30)),
            //               border: Border.all(
            //                 width: 1,
            //                 color: Color(0xffCBB397),
            //               ),
            //             ),
            //             child: Text(
            //               titleStr,
            //               style: TextStyle(
            //                 color: Color(0xffCBB397),
            //                 fontSize: 10,
            //               ),
            //             ),
            //           );
            //         }).toList(),
            //       ),
            //       SizedBox(
            //         height: setWidth(14),
            //       ),
            //     ],
            //   ),
            // ),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Expanded(
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text.rich(
                        TextSpan(
                          children: [
                            TextSpan(
                              text: tiShi + '¥',
                              style: TextStyle(
                                color: Color(0xffea5504),
                                fontSize: 10,
                              ),
                            ),
                            TextSpan(
                              text: parsePrice(priceStr),
                              style: TextStyle(
                                color: Color(0xffea5504),
                                fontSize: 16,
                              ),
                            ),
                            // WidgetSpan(
                            //   child: SizedBox(width: 3),
                            // ),
                            // TextSpan(
                            //   text: listMap[index]['commission_amount'] > 0 ? '赚${listMap[index]['commission_amount']}' : '',
                            //   style: TextStyle(
                            //     color: Color(0xffdd2f3e),
                            //     fontSize: 10,
                            //   ),
                            // ),
                          ],
                        ),
                      ),
                      Text(
                        oldBool ? '¥${parsePrice(oldPriceStr)}' : '',
                        style: TextStyle(
                          color: Color(0xff999999),
                          fontSize: 11,
                          decoration: TextDecoration.lineThrough,
                        ),
                      ),
                    ],
                  ),
                ),
                // InkWell(
                //   onTap: () {
                //     print(' 加入购物车图片点击事件！！！ index = $index');
                //     if (!soldOutBool) {
                //       if (listMap[index]['nospec'] == '1') {
                //         logic.addShoppingCart(
                //           ec_shop_num_id:
                //               listMap[index]['shop_num_id'].toString(),
                //           item_num_id:
                //               listMap[index]['default_item_num_id'].toString(),
                //           style_num_id:
                //               listMap[index]['style_num_id'].toString(),
                //           ec_style_num_id:
                //               listMap[index]['ec_style_num_id'].toString(),
                //         );
                //       }
                //     }
                //   },
                //   child: Image.asset(
                //     'assets/images/shoppingCart_image.png',
                //     width: setWidth(42),
                //     height: setWidth(42),
                //     color: !soldOutBool ? Color(0xffEA5504) : Color(0xffcccccc),
                //     fit: BoxFit.cover,
                //   ),
                // ),
              ],
            ),
          ],
        ),
      ),
    );
  }

  // 竖排 每行一列
  _verticalSingleItemWidget({int index}) {
    String priceStr = '', oldPriceStr = '', tiShi = '';
    bool oldBool = false;
    if (listMap[index]['is_seckill'] == 1) {
      // 秒杀商品
      priceStr = listMap[index]['price'].toString();
      oldBool = listMap[index]['mkt_price'] > listMap[index]['price']; // 显示旧价格
      oldPriceStr = listMap[index]['mkt_price'].toString();
    } else if (listMap[index]['is_pre_sale'] == 1) {
      priceStr = listMap[index]['price'].toString();
      oldBool = listMap[index]['mkt_price'] > listMap[index]['price']; // 显示旧价格
      oldPriceStr = listMap[index]['mkt_price'].toString();
    } else {
      if (listMap[index]['expect_price'] > 0) {
        priceStr = '${listMap[index]['expect_price'].toString()}';
        tiShi = '折后';
        oldBool = listMap[index]['mkt_price'] >
            listMap[index]['expect_price']; // 显示旧价格
        oldPriceStr = listMap[index]['mkt_price'].toString();
      } else {
        priceStr = listMap[index]['price'].toString();
        oldBool =
            listMap[index]['mkt_price'] > listMap[index]['price']; // 显示旧价格
        oldPriceStr = listMap[index]['mkt_price'].toString();
      }
    }
    bool soldOutBool = listMap[index]['style_store'] <= 0;
    // print('=====================soldOutBool = $soldOutBool, ${listMap[index]['style_store']}');
    // 标签
    bool labelBool = false;
    String labelStr = '';
    if (angleInformationList.length > 0) {
      Map labelMap = angleInformationList[index];
      if (labelMap['item_promotion']['parameter_corner'] != null &&
          labelMap['item_promotion']['parameter_corner'] != '') {
        labelStr = labelMap['item_promotion']['parameter_corner'];
        labelBool = true;
      }
    }

    return InkWell(
      onTap: () {
        String itemNumId =
            listMap[index]['default_item_num_id']?.toString() ?? '';
        String styleNumId = listMap[index]['style_num_id']?.toString() ?? '';
        String shopId = listMap[index]['shop_num_id']?.toString() ?? '';
        String cat1Id = listMap[index]['cat1_id']?.toString() ?? '';
        String ecStyleNumId =
            listMap[index]['ec_style_num_id'].toString() ?? '';
        Get.toNamed(RouteConfig.goodsDetail, arguments: {
          'itemNumId': itemNumId,
          'styleNumId': styleNumId,
          'shopId': shopId,
          'cat1Id': cat1Id,
          'ecStyleNumId': ecStyleNumId,
          'typeIndex': listMap[index]['is_pre_sale'],
        });
      },
      child: Container(
        color: Colors.white,
        child: Column(
          children: [
            SizedBox(
              height: setWidth(30),
            ),
            Padding(
              padding: EdgeInsets.symmetric(horizontal: setWidth(20)),
              child: Row(
                children: [
                  Stack(
                    children: [
                      CachedImage(
                        width: setWidth(120),
                        height: setWidth(120),
                        margin: EdgeInsets.zero,
                        scale: BoxFit.fill,
                        path: listMap[index]['image_default_id'],
                      ),
                      Positioned(
                        left: setWidth(0),
                        top: setWidth(0),
                        child: soldOutBool
                            ? Container(
                                width: setWidth(120),
                                height: setWidth(120),
                                alignment: Alignment.center,
                                decoration: BoxDecoration(
                                  color: Color(0xffbbbbbb).withOpacity(0.7),
                                  borderRadius:
                                      BorderRadius.circular(setWidth(60)),
                                ),
                                child: Text(
                                  '售罄',
                                  style: TextStyle(
                                    color: Colors.white,
                                    fontSize: 15,
                                  ),
                                ),
                              )
                            : SizedBox(),
                      ),
                    ],
                  ),
                  SizedBox(
                    width: setWidth(20),
                  ),
                  Expanded(
                    child: Container(
                      height: setWidth(136),
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text(
                            listMap[index]['title'],
                            maxLines: 1,
                            overflow: TextOverflow.ellipsis,
                            style: TextStyle(
                              color: Color(0xff222222),
                              fontSize: 13,
                            ),
                          ),
                          Row(
                            mainAxisAlignment: MainAxisAlignment.start,
                            children: [
                              if (listMap[index]['is_seckill'] == 1)
                                Container(
                                  constraints: BoxConstraints(
                                    maxWidth: setWidth(220),
                                    minWidth: 0,
                                  ),
                                  height: setWidth(26),
                                  padding: EdgeInsets.symmetric(
                                      horizontal: setWidth(4)),
                                  decoration: BoxDecoration(
                                    borderRadius:
                                        BorderRadius.circular(setWidth(4)),
                                    border: Border.all(
                                      width: setWidth(1),
                                      color: Colors.red,
                                    ),
                                  ),
                                  child: Text(
                                    "秒杀",
                                    maxLines: 1,
                                    overflow: TextOverflow.ellipsis,
                                    style: TextStyle(
                                      color: Colors.red,
                                      fontSize: 18.sp,
                                      height: 1.3,
                                    ),
                                  ),
                                ),
                              if (listMap[index]['is_pre_sale'] == 1)
                                Container(
                                  constraints: BoxConstraints(
                                    maxWidth: setWidth(220),
                                    minWidth: 0,
                                  ),
                                  height: setWidth(26),
                                  padding: EdgeInsets.symmetric(
                                      horizontal: setWidth(4)),
                                  decoration: BoxDecoration(
                                    borderRadius:
                                        BorderRadius.circular(setWidth(4)),
                                    border: Border.all(
                                      width: setWidth(1),
                                      color: Color(0xff48C13D),
                                    ),
                                  ),
                                  child: Text(
                                    "预售",
                                    maxLines: 1,
                                    overflow: TextOverflow.ellipsis,
                                    style: TextStyle(
                                      color: Color(0xff48C13D),
                                      fontSize: 18.sp,
                                      height: 1.3,
                                    ),
                                  ),
                                ),
                              Container(
                                constraints: BoxConstraints(
                                  maxWidth: setWidth(400),
                                  minWidth: 0,
                                ),
                                height: setWidth(26),
                                margin: EdgeInsets.only(left: 5),
                                padding: EdgeInsets.symmetric(
                                    horizontal: setWidth(4)),
                                decoration: labelBool
                                    ? BoxDecoration(
                                        borderRadius:
                                            BorderRadius.circular(setWidth(4)),
                                        border: Border.all(
                                          width: setWidth(1),
                                          color: Colors.red,
                                        ),
                                      )
                                    : null,
                                child: labelBool
                                    ? Text(
                                        labelStr,
                                        maxLines: 1,
                                        overflow: TextOverflow.ellipsis,
                                        style: TextStyle(
                                          color: Colors.red,
                                          fontSize: 18.sp,
                                          height: 1.3,
                                        ),
                                      )
                                    : null,
                              ),
                            ],
                          ),
                          Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Expanded(
                                child: Column(
                                  crossAxisAlignment: CrossAxisAlignment.start,
                                  children: [
                                    Text.rich(
                                      TextSpan(
                                        children: [
                                          TextSpan(
                                            text: tiShi + '¥',
                                            style: TextStyle(
                                              color: Color(0xffea5504),
                                              fontSize: 10,
                                            ),
                                          ),
                                          TextSpan(
                                            text: parsePrice(priceStr),
                                            style: TextStyle(
                                              color: Color(0xffea5504),
                                              fontSize: 16,
                                            ),
                                          ),
                                          // WidgetSpan(
                                          //   child: SizedBox(width: 3),
                                          // ),
                                          // TextSpan(
                                          //   text: listMap[index]['commission_amount'] > 0 ? '赚${listMap[index]['commission_amount']}' : '',
                                          //   style: TextStyle(
                                          //     color: Color(0xffdd2f3e),
                                          //     fontSize: 10,
                                          //   ),
                                          // ),
                                        ],
                                      ),
                                    ),
                                    Offstage(
                                      offstage: !oldBool,
                                      child: Text(
                                        '¥${parsePrice(oldPriceStr)}',
                                        style: TextStyle(
                                          color: Color(0xff999999),
                                          fontSize: 11,
                                          decoration:
                                              TextDecoration.lineThrough,
                                        ),
                                      ),
                                    ),
                                  ],
                                ),
                              ),
                              // InkWell(
                              //   onTap: () {
                              //     print(' 加入购物车图片点击事件！！！ index = $index');
                              //     if (!soldOutBool) {
                              //       if (listMap[index]['nospec'] == '1') {
                              //         logic.addShoppingCart(
                              //           ec_shop_num_id: listMap[index]
                              //                   ['shop_num_id']
                              //               .toString(),
                              //           item_num_id: listMap[index]
                              //                   ['default_item_num_id']
                              //               .toString(),
                              //           style_num_id: listMap[index]
                              //                   ['style_num_id']
                              //               .toString(),
                              //           ec_style_num_id: listMap[index]
                              //                   ['ec_style_num_id']
                              //               .toString(),
                              //         );
                              //       }
                              //     }
                              //   },
                              //   child: Image.asset(
                              //     'assets/images/shoppingCart_image.png',
                              //     width: setWidth(42),
                              //     height: setWidth(42),
                              //     color: !soldOutBool
                              //         ? Color(0xffEA5504)
                              //         : Color(0xffcccccc),
                              //     fit: BoxFit.cover,
                              //   ),
                              // ),
                            ],
                          ),
                        ],
                      ),
                    ),
                  ),
                ],
              ),
            ),
            SizedBox(
              height: setWidth(10),
            ),
            Divider(
              height: setWidth(1),
              color: Color(0xffcccccc),
              indent: setWidth(160),
              endIndent: 0,
            ),
          ],
        ),
      ),
    );
  }
}
